package com.lxy.mychat1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.media.Image;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.lxy.mychat1.Adapter.PyqItemAdapter;
import com.lxy.mychat1.Bean.PyqItem;

import org.litepal.LitePal;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class PyqActivity extends AppCompatActivity {
    private ImageView postpyq,userimg;
    private ListView  pyqlv;
    private TextView  username;
    PyqItemAdapter adapter;
    List<PyqItem> pyqItemList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pyq);
        initView();
        setListener();

    }

    private void setListener() {
        postpyq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it=new Intent(PyqActivity.this,PostActivity.class);
                startActivity(it);
                finish();
            }
        });
    }

    private void initView() {
        postpyq=findViewById(R.id.postpyq);
        pyqlv=findViewById(R.id.pyqlv);
        username=findViewById(R.id.username);
        userimg=findViewById(R.id.pyquserimg);

        pyqItemList= LitePal.findAll(PyqItem.class);
        Collections.reverse(pyqItemList);
        pyqlv.setAdapter(adapter);
        adapter=new PyqItemAdapter(PyqActivity.this,R.layout.pyq_item,pyqItemList);
        //pyqlv.setAdapter(adapter);
        SharedPreferences sharedPreferences=getSharedPreferences("userinfo",MODE_PRIVATE);
        userimg.setImageResource(sharedPreferences.getInt("myimg",-1));
        username.setText(sharedPreferences.getString("myname",""));

    }
}
